from symbide import PATHS
from os import listdir, remove
import os.path

def createUniquePath(dir, name, extension='.png', return_name=False):
    '''
    Searches a not used filename in the 'temp_pictures' directory 
    and creates an empty file. Saves the path into self.path.
    '''
    
    l = listdir(dir)
    i=0
    while True:
        n = name+str(i)+extension
        if not n in l:
            path = os.path.join(dir, n)
            break
        i+=1
    f = open(path, 'w')
    f.close()
    if return_name:
        return path, n
    return path

def deleteTempPlots():
    '''
    Deletes all png-files in the temp_picture directory
    '''
    
    dir = PATHS['temp_pictures']
    files = listdir(dir)
    for f in files:
        p = os.path.join(dir,f)
        if os.path.isfile(p) and not os.path.splitext(f)[1]=='':
            remove(p)